package com.yu.smsinterceptor.dao;

import com.yu.smsinterceptor.XUtilsApplication;
import com.yu.smsinterceptor.mode.Phone;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

public class PhoneDao {

    private DbManager db = x.getDb(XUtilsApplication.getDaoConfig());

    /**
     * 新增
     * @param p
     */
    public void save(Phone p) {
        try {
            db.save(p);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据id查找
     * @param id
     */
    public Phone get(Long id) {
        try {
            return db.findById(Phone.class, id);
        } catch (DbException e) {
            e.printStackTrace();
        }

        return null;
    }

    public List<Phone> list() {
        try {
            return db.findAll(Phone.class);
        } catch (DbException e) {
            e.printStackTrace();
        }

        return null;
    }

    public void delete(Long id) {
        try {
            db.deleteById(Phone.class, id);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }

}
